//
//  MonthDropVC.swift
//  Drop
//
//  Created by zhuxuhong on 2018/3/17.
//  Copyright © 2018年 zhuxuhong. All rights reserved.
//

import UIKit

class MonthDropCell: UICollectionViewCell {
    @IBOutlet weak var imageView: UIImageView!
    @IBOutlet weak var label: UILabel!
}

class MonthDropVC: UIViewController {

    @IBOutlet weak var collectionView: UICollectionView!
    
    var data: [String] = ["", "", ""]
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }

    func attributedDateText(day: Int, month: Int) -> NSAttributedString {
        let attr1 = NSAttributedString(string: "\(day)", font: .boldSystemFont(ofSize: 40), color: .white, lineHeightMultiple: 1)
        let attr2 = NSAttributedString(string: " / \(month)月", font: .systemFont(ofSize: 16), color: .white, lineHeightMultiple: 1)
        return NSMutableAttributedString(attrStrings: [attr1, attr2])
    }
}

extension MonthDropVC: UICollectionViewDelegateFlowLayout{
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let width = (view.width - 3 * 20) / 2
        return CGSize(both: width)
    }
}

extension MonthDropVC: UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return data.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueCell(withClass: MonthDropCell.self, for: indexPath)!
        
        cell.label.attributedText = attributedDateText(day: indexPath.item + 1, month: 3)
        
        return cell
    }
}
